<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div id="test"></div>

  <script src="./js/react.development.js"></script>
  <script src="./js/react-dom.development.js"></script>
  <script src="./js/babel.min.js"></script>
  <script type="text/babel">
    // state状态，也是数据
    class Weather extends React.Component {
      state = { isHot: false, wind: '微风' }

      render() {
        const { isHot, wind } = this.state
        return <h1><span onClick={this.changeWeather}
          style={{ cursor: 'pointer' }}>{isHot ? '炎热' : '凉爽'}</span>,{wind}</h1>
      }

      // 箭头函数，this继承外层的作用域的this，指向Weather组件实例
      changeWeather = () => {
        const isHot = this.state.isHot
        this.setState({ isHot: !isHot })
        console.log(this)
      }

      // 普通函数。如果是实例调用，this指向调用者；如果是直接调用(onClick=Fn这种形式)，则指向window全局对象，但是由于开启了局部的严格模式，所以是undefined
      changeWeather2() {
        console.log(this)
      }
    }

    ReactDOM.render(<Weather />, document.getElementById('test'))
  </script>

</body>

</html>